/**
 * @description 判断是否为本地icon
 * @param iconName {string}
 * @return boolean
 */
export function isLocalIcon(iconName: string): boolean {
  const reg = /^icon-./
  return reg.test(iconName)
}

/**
 * @description 判断是否为icon-pack
 * @param iconName string
 * @return boolean
 */
export function isParkIcon(iconName: string): boolean {
  const reg = /^i-./
  return reg.test(iconName)
}

type iconInfo = {
  iconName: string | undefined
  iconMode: 'local' | 'park' | undefined
}
/**
 * @description 得到真实icon名与模式
 * @param icon string
 * @return iconInfo
 */
export function getRelIconInfo(icon: string): iconInfo {
  let iconName, iconMode
  if (isLocalIcon(icon)) {
    iconName = icon.replace('icon-', '')
    iconMode = 'local'
  } else if (isParkIcon(icon)) {
    iconName = icon
    iconMode = 'park'
  } else {
    console.warn('请传入正确的本地/icon-pack图标')
  }
  return { iconName, iconMode }
}
